package site.wanjiahao.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Time {

    private static final SimpleDateFormat fmt = new SimpleDateFormat("HH:mm:ss.SSS");

    public interface Task {

        void execute();

    }

    public static void execute(String title, Task task) {
        if (task == null) return;
        title = (title == null) ? "" : ("【" + title + "】");
        String finalTitle = title;
       new Thread(() -> {
           System.out.println("开始：" + fmt.format(new Date()));
           long begin = System.currentTimeMillis();
           task.execute();
           long end = System.currentTimeMillis();
           System.out.println("结束：" + fmt.format(new Date()));
           double delta = (end - begin) / 1000.0;
           System.out.println("耗时：" + delta + "秒");
           System.out.println("-------------------------------------");
           System.out.println(finalTitle);
        }).start();


    }


}
